// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_FIN_MAP_IO_BPA
// * CreateDate    : 2012/2/2 10:17:12
// * Creater       : CodeSmith
// * LastChangeDate: 2012/2/2 10:17:12
// * LastChanger   : 2012/2/2 10:17:12
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Fin
{
/// <summary>
    /// FinMapIoBpa
    /// </summary>
    public partial class FinMapIoBpaBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objFinMapIoBpaEntity">Entity</param>
        /// <returns>Entity</returns>
        public static FinMapIoBpaEntity GetFinMapIoBpa(FinMapIoBpaEntity objFinMapIoBpaEntity)
        {
            return DataAccess.SelectSingle<FinMapIoBpaEntity>(objFinMapIoBpaEntity);
        }
        public static List<FinMapIoBpaEntity> GetByApplicationID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            FinMapIoBpaEntity entity = new FinMapIoBpaEntity();
            entity.ApplicationId = id;
            return DataAccess.Select<FinMapIoBpaEntity>(entity);
        }
        public static List<FinMapIoBpaEntity> GetByImportItemID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            FinMapIoBpaEntity entity = new FinMapIoBpaEntity();
            entity.ImportItemId = id;
            return DataAccess.Select<FinMapIoBpaEntity>(entity);
        }
        public static List<InvImportItemEntity> GetImportItemByApplicationID(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            string sql = @"SELECT ITEM.*
                            FROM FIN_BILLING_PAID_APPLICATION BPA
                            INNER JOIN FIN_MAP_IO_BPA MAP ON MAP.APPLICATION_ID = BPA.APPLICATION_ID
							INNER JOIN INV_IMPORT_ITEM ITEM ON ITEM.IMPORT_ITEM_ID = MAP.IMPORT_ITEM_ID
                            INNER JOIN INV_IMPORT_ORDER IMP ON IMP.IMPORT_ORDER_ID = ITEM.IMPORT_ORDER_ID
                            WHERE BPA.APPLICATION_ID = '" + id + "'";
            return DataAccess.Select<InvImportItemEntity>(sql);
        }
        public static DataTable GetImportByAppId(string appId)
        {
            if (appId == null)
            {
                return null;
            }
            string sql = @"SELECT ITEM.*, P.PRODUCT_CODE,P.PRODUCT_SPEC_OUT, P.PRODUCT_SPEC_IN, P.PRODUCT_NAME, O.ORDER_CODE,O.ORDER_DATE, MP.NAME_CN AS ORDER_PERSON_NAME
                            FROM INV_IMPORT_ITEM ITEM
                            INNER JOIN INV_IMPORT_ORDER O ON O.IMPORT_ORDER_ID = ITEM.IMPORT_ORDER_ID
                            INNER JOIN FIN_MAP_IO_BPA MAP ON MAP.IMPORT_ITEM_ID = ITEM.IMPORT_ITEM_ID
                            LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = ITEM.PRODUCT_ID
							LEFT JOIN MST_PERSON MP ON MP.PERSON_ID = O.ORDER_PERSON
                            WHERE MAP.APPLICATION_ID = '" + appId + "'";
            return DataAccess.SelectDataSet(sql).Tables[0];
        }
        public static DataTable GetImportByBillingId(string billingId)
        {
            if (billingId == null)
            {
                return null;
            }
            string sql = @"SELECT ITEM.*, MAP.*, P.PRODUCT_CODE,P.PRODUCT_SPEC_OUT, P.PRODUCT_SPEC_IN, P.PRODUCT_NAME, O.ORDER_CODE,O.ORDER_DATE, MP.NAME_CN AS ORDER_PERSON_NAME
                            FROM INV_IMPORT_ITEM ITEM
                            INNER JOIN INV_IMPORT_ORDER O ON O.IMPORT_ORDER_ID = ITEM.IMPORT_ORDER_ID
                            INNER JOIN FIN_MAP_BILLING_IMPORT MAP ON MAP.IMPORT_ITEM_ID = ITEM.IMPORT_ITEM_ID
                            LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = ITEM.PRODUCT_ID
							LEFT JOIN MST_PERSON MP ON MP.PERSON_ID = O.ORDER_PERSON
                            WHERE MAP.BILLING_ID = '" + billingId + "'";
            return DataAccess.SelectDataSet(sql).Tables[0];
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objFinMapIoBpaEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertFinMapIoBpa(FinMapIoBpaEntity objFinMapIoBpaEntity)
        {
            return DataAccess.Insert(objFinMapIoBpaEntity);
        }

        public static bool InsertFinMapIoBpa(List<FinMapIoBpaEntity> objFinMapIoBpaEntityList)
        {
            return DataAccess.Insert(objFinMapIoBpaEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objFinMapIoBpaEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateFinMapIoBpa(FinMapIoBpaEntity objFinMapIoBpaEntity)
        {
            return DataAccess.Update(objFinMapIoBpaEntity);
        }

        public static bool UpdateFinMapIoBpa(List<FinMapIoBpaEntity> objFinMapIoBpaEntityList)
        {
            return DataAccess.Update<FinMapIoBpaEntity>(objFinMapIoBpaEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objFinMapIoBpaEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteFinMapIoBpa(FinMapIoBpaEntity objFinMapIoBpaEntity)
        {
            return DataAccess.Delete(objFinMapIoBpaEntity);
        }

        public static bool DeleteFinMapIoBpa(List<FinMapIoBpaEntity> objFinMapIoBpaEntityList)
        {
            return DataAccess.Delete<FinMapIoBpaEntity>(objFinMapIoBpaEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetFinMapIoBpaAll()
        {
            return DataAccess.SelectAllDataSet<FinMapIoBpaEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<FinMapIoBpaEntity> GetFinMapIoBpaAllList()
        {
            return DataAccess.SelectAll<FinMapIoBpaEntity>();
        }
        #endregion
	}
	
	
}	

